package JiHeDemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * @author 86150
 */
public class TestList {
	public static void main(String[] args) {
		List list = new ArrayList();
		list.add("苹果");
		list.add("小米");
		list.add("华为");
		System.out.println("元素个数" + list.size());
		System.out.println(list);
		System.out.println("11111111111");
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
		System.out.println("22222222222");
		for (Object o : list) {
			System.out.println(o.toString());
		}
		System.out.println("33333333333");
		Iterator it = list.iterator();
		while (it.hasNext()) {
			System.out.println(it.next().toString());
		}
		System.out.println("4444444444444");
		//列表迭代器
		System.out.println("=====从前往后=====");
		ListIterator lit = list.listIterator();
		while (lit.hasNext()) {
			System.out.println(lit.nextIndex() + ":" + lit.next());
		}
		System.out.println("=====从后往前====");
		while (lit.hasPrevious()) {
			System.out.println(lit.previousIndex() + ":" + lit.previous());
		}
		//判断有没有
		System.out.println(list.contains("华为"));
		//判断是否为空
		System.out.println(list.isEmpty());
		System.out.println("===获取元素位置");
		System.out.println(list.indexOf("华为"));
	}
}
